package com.zksk.admin.mapper.market;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zksk.admin.domain.market.dto.SaleRecordDto;
import com.zksk.mbg.admin.domain.SaleRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SaleRecordDao extends BaseMapper<SaleRecord> {

    @Select("select sr.*,\n" +
            "(select user_name from sys_user where user_id = sr.user_id) as user_name,\n" +
            "(select member_name from platform_fact_member where member_id = sr.member_id) as member_name,\n" +
            "'' as stations_name, \n" +
            "(select customer_name from platform_customer where customer_id = sr.customer_id) as customer_name,\n" +
            "m.plan_time,\n" +
            "mo.operator_name,\n" +
            "mo.operator_phone\n" +
            "from platform_fact_sale_record sr\n" +
            "left join platform_fact_member m on m.member_id = sr.member_id\n" +
            "left join platform_fact_member_operator mo on sr.member_id = mo.member_id\n" +
            "where sr.member_id = '${memberId}'\n" +
            "and sr.del_flag = '0'\n" +
            "and mo.default_op = '0'\n" +
            "order by sr.create_time desc")
    List<SaleRecordDto> selectSaleRecordList(Long memberId);
}
